package it.sd.pwframework.admin.bean;

import it.sd.pwframework.business.bean.PwForm;
import it.sd.pwframework.business.service.CommonService;

import java.util.HashMap;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import javax.persistence.Transient;

@ManagedBean(name="selectorsJsfBean")
@SessionScoped
public class SelectorsJsfBean extends HashMap<String, SelectorBean> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@ManagedProperty(value="#{commonService}")
	@Transient
    private transient CommonService commonService;

	public CommonService getCommonService() {
		return commonService;
	}

	public void setCommonService(CommonService commonService) {
		this.commonService = commonService;
	}

	@Override
	public SelectorBean get(Object key) {
		String selectorName = key.toString();
		
		SelectorBean bean = super.get(selectorName);
		if (bean==null) {
			PwForm subform = commonService.getFormByClassname(selectorName);
			bean = new SelectorBean(subform, commonService);
			put(selectorName, bean);
		}
		
		return bean;
	}


	
	
	
}
